<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for service\RSIService.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">all files</a> / <a href="index.html">service/</a> RSIService.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">97.96% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>48/49</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">91.67% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>22/24</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>5/5</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">97.92% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>47/48</span>
      </div>
    </div>
  </div>
  <div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-yes">195×</span>
<span class="cline-any cline-yes">27×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">168×</span>
<span class="cline-any cline-yes">44×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">124×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-yes">26×</span>
<span class="cline-any cline-yes">20×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">20×</span>
<span class="cline-any cline-yes">20×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">46×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">42×</span>
<span class="cline-any cline-yes">25×</span>
<span class="cline-any cline-yes">25×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">17×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Injectable } from '@angular/core';
&nbsp;
import { QuoteBasic } from 'service/QuoteBasic';
import { IRSIService } from 'interface/IRSIService';
&nbsp;
@Injectable()
export class RSIService implements IRSIService {
&nbsp;
  connection;
&nbsp;
  constructor() {
&nbsp;
  }
&nbsp;
  private _cacuRSI(close:Array&lt;number&gt;, open:Array&lt;number&gt;, start:number, end:number):number {
&nbsp;
    let upSum = 0;
    let downSum = 0;
&nbsp;
    let rsi = 50.00;
&nbsp;
    // if(start === end) {
    //   return rsi;
    // }
&nbsp;
    for(let j=start; j&lt;=end; j++) {
      if(j === 0){
        continue;
      }
&nbsp;
      if ((close[j] - close[j-1]) &gt; 0) {
        upSum += (close[j] - close[j-1]);
      } else {
        downSum += (close[j-1] - close[j]);
      }
    }
&nbsp;
    if (downSum === 0 &amp;&amp; upSum === 0) {
      rsi = 50.00;
    } else <span class="missing-if-branch" title="if path not taken" >I</span>if (downSum === 0 &amp;&amp; <span class="branch-1 cbranch-no" title="branch not covered" >upSum !== 0)</span> {
<span class="cstat-no" title="statement not covered" >      rsi = 100.00;</span>
    } else {
      const rs = ((upSum/(end-start+1)) / (downSum/(end-start+1))).toFixed(4);
      rsi = parseFloat((100 * parseFloat(rs)/(1 + parseFloat(rs))).toFixed(4));
    }
&nbsp;
    return rsi;
  }
&nbsp;
  compute(quote:QuoteBasic, day:number):Array&lt;any&gt; {
    const close = quote.close;
    const open  = quote.open;
    const count = close.length;
    const rsiList = [];
    const times = quote.time;
    if (day &gt; 0) {
      for(let i=0; i&lt;count; i++) {
        if(i &lt; day) {
          rsiList.push(this._cacuRSI(close, open, 0, i));
          continue;
        }
&nbsp;
        rsiList.push(this._cacuRSI(close, open, i-day+1, i));
      }
    }
&nbsp;
    return rsiList;
  }
&nbsp;
  update(quote:QuoteBasic, day:number, oldList:Array&lt;any&gt;):Array&lt;any&gt; {
    const close = quote.close;
    const open  = quote.open;
    const count = close.length;
    const originCount = close.length;
    const oldCount = oldList.length;
    const times = quote.time;
&nbsp;
    if(oldCount === 0){
      return this.compute(quote, day);
    }
&nbsp;
    const start = (originCount - day) &lt; 0 ? 0 : (originCount - day);
    const end = (originCount - 1) &lt; 0 ? 0 : (originCount - 1);
&nbsp;
    const rsi = this._cacuRSI(close, open, start, end);
&nbsp;
    if (oldCount &lt; originCount) {
      oldList.push(rsi);
    } else {
      oldList[end] = rsi;
    }
&nbsp;
    return oldList;
&nbsp;
  }
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Jul 24 2017 16:45:57 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
